<template>
  <div style="height: 100%">
    <a-spin :spinning="loading" wrapperClassName="spinning-container">
      <section class="organization-container">
        <page-header :title="l('OrganizationUnits')"></page-header>
        <a-row class="organization">
          <a-col :span="6" class="organization-unit-tree-panel">
            <organization-unit-tree-panel
              onsublime="return false;"
              @selectedNode="selectedNodeFunc"
            ></organization-unit-tree-panel>
          </a-col>
          <a-col :span="18" class="organization-unit-tree-panel">
            <a-row class="units-header">
              <a-col :span="19" class="title">
                <team-outlined />
                <span v-if="selectedTree && selectedTree.hasOwnProperty('id')">
                  {{ selectedTree.displayName }}
                </span>
              </a-col>
            </a-row>
            <a-row>
              <!-- 暂无数据 -->
              <div class="no-data" v-if="!selectedTree || !selectedTree.hasOwnProperty('id')">
                <a-empty :description="l('SelectAnOrganizationUnitToSeeMembers')" />
                <!-- <p>{{ l('SelectAnOrganizationUnitToSeeMembers') }}</p> -->
              </div>
              <a-tabs
                defaultActiveKey="1"
                v-show="selectedTree && selectedTree.hasOwnProperty('id')"
              >
                <!-- 用户 -->
                <a-tab-pane :tab="l('Users')" key="1" :forceRender="false">
                  <organization-unit-members-panel
                    v-if="selectedTree"
                    :selectTree="selectedTree"
                  ></organization-unit-members-panel>
                </a-tab-pane>
                <!-- 角色 -->
                <a-tab-pane :tab="l('Roles')" key="2" :forceRender="true">
                  <organization-unit-role-panel
                    v-if="selectedTree"
                    :selectTree="selectedTree"
                  ></organization-unit-role-panel>
                </a-tab-pane>
              </a-tabs>
            </a-row>
          </a-col>
        </a-row>
      </section>
    </a-spin>
  </div>
</template>

<script lang="ts">
  import { AppComponentBase } from '/@/shared/component-base';
  import OrganizationUnitTreePanel from './organization-unit-tree-panel/organizaion-unit-tree-panel.vue';
  import OrganizationUnitMembersPanel from './organization-unit-members-panel/organization-unit-members-panel.vue';
  import OrganizationUnitRolePanel from './organization-unit-role-panel/organization-unit-role-panel.vue';
  import { TeamOutlined } from '@ant-design/icons-vue';
  import { defineComponent } from 'vue';

  export default defineComponent({
    name: 'organization-units',
    components: {
      OrganizationUnitTreePanel,
      OrganizationUnitMembersPanel,
      OrganizationUnitRolePanel,
      TeamOutlined,
    },
    mixins: [AppComponentBase],
    data() {
      return {
        // 选择的树结构
        selectedTree: null as any,
        showtab: false,
      };
    },

    methods: {
      /**
       * 选择树结构
       */
      selectedNodeFunc(data) {
        this.selectedTree = data;
      },
    },
  });
</script>

<style scoped lang="less">
  :deep(.ant-tabs-nav) {
    padding-left: 24px;
  }
  .organization {
    min-height: 85vh;
    display: flex;
  }
  .content {
    padding: 24px;
    width: 100%;
  }
  .organization-unit-tree-panel {
    background-color: #fff;
    border: 1px solid #e8e8e8;
  }
  .units-header {
    height: 50px;
    border-bottom: 1px solid #e8e8e8;
    > .title {
      line-height: 50px;
      font-size: 16px;
      color: rgba(0, 0, 0, 0.85);
      font-weight: 500;
      margin-left: 20px;
    }
    p {
      line-height: 50px;
      &.left {
        font-size: 16px;
        color: rgba(0, 0, 0, 0.85);
        font-weight: 500;
        margin-left: 20px;
      }
      a {
        margin-left: 10px;
      }
    }
  }
  :deep(.ant-tabs-bar) {
    margin: 0 20px;
  }
  // 暂无数据
  .no-data {
    width: 350px;
    position: relative;
    top: 150px;
    left: 35%;
    p {
      padding: 0 12px 0 12px;
      text-align: center;
      margin-bottom: 0;
      line-height: 120px;
    }
  }
  :deep(.ant-tabs) {
    width: 100%;
  }
</style>
